﻿// Type: System.Array
// Assembly: mscorlib, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
// Assembly location: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\mscorlib.dll

using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;

namespace System
{
  /// <summary>
  /// Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.
  /// </summary>
  [ComVisible(true)]
  public abstract class Array : ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable
  {
    internal const int MaxArrayLength = 2146435071;

    /// <summary>
    /// Gets a 32-bit integer that represents the total number of elements in all the dimensions of the <see cref="T:System.Array"/>; zero if there are no elements in the array.
    /// </summary>
    /// 
    /// <returns>
    /// A 32-bit integer that represents the total number of elements in all the dimensions of the <see cref="T:System.Array"/>.
    /// </returns>
    public int Length { [SecuritySafeCritical, ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    /// Gets the zero-based rank (number of dimensions) of the <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// The zero-based rank (number of dimensions) of the <see cref="T:System.Array"/>.
    /// </returns>
    public int Rank { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), SecuritySafeCritical, MethodImpl(MethodImplOptions.InternalCall)] get; }

    int ICollection.Count
    {
      get
      {
        return this.Length;
      }
    }

    /// <summary>
    /// Gets an object that can be used to synchronize access to the <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// An object that can be used to synchronize access to the <see cref="T:System.Array"/>.
    /// </returns>
    public object SyncRoot
    {
      get
      {
        return (object) this;
      }
    }

    /// <summary>
    /// Gets a value indicating whether the <see cref="T:System.Array"/> is read-only.
    /// </summary>
    /// 
    /// <returns>
    /// This property is always false for all arrays.
    /// </returns>
    public bool IsReadOnly
    {
      get
      {
        return false;
      }
    }

    /// <summary>
    /// Gets a value indicating whether the <see cref="T:System.Array"/> has a fixed size.
    /// </summary>
    /// 
    /// <returns>
    /// This property is always true for all arrays.
    /// </returns>
    public bool IsFixedSize
    {
      get
      {
        return true;
      }
    }

    /// <summary>
    /// Gets a value indicating whether access to the <see cref="T:System.Array"/> is synchronized (thread safe).
    /// </summary>
    /// 
    /// <returns>
    /// This property is always false for all arrays.
    /// </returns>
    public bool IsSynchronized
    {
      get
      {
        return false;
      }
    }

    internal Array()
    {
    }

    /// <summary>
    /// Returns a read-only wrapper for the specified array.
    /// </summary>
    /// 
    /// <returns>
    /// A read-only <see cref="T:System.Collections.ObjectModel.ReadOnlyCollection`1"/> wrapper for the specified array.
    /// </returns>
    /// <param name="array">The one-dimensional, zero-based array to wrap in a read-only <see cref="T:System.Collections.ObjectModel.ReadOnlyCollection`1"/>  wrapper. </param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception>
    public static ReadOnlyCollection<T> AsReadOnly<T>(T[] array)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      else
        return new ReadOnlyCollection<T>((IList<T>) array);
    }

    /// <summary>
    /// Changes the number of elements of an array to the specified new size.
    /// </summary>
    /// <param name="array">The one-dimensional, zero-based array to resize, or null to create a new array with the specified size.</param><param name="newSize">The size of the new array.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="newSize"/> is less than zero.</exception>
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static void Resize<T>(ref T[] array, int newSize)
    {
      if (newSize < 0)
        throw new ArgumentOutOfRangeException("newSize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      T[] objArray1 = array;
      if (objArray1 == null)
      {
        array = new T[newSize];
      }
      else
      {
        if (objArray1.Length == newSize)
          return;
        T[] objArray2 = new T[newSize];
        Array.Copy((Array) objArray1, 0, (Array) objArray2, 0, objArray1.Length > newSize ? newSize : objArray1.Length);
        array = objArray2;
      }
    }

    /// <summary>
    /// Creates a one-dimensional <see cref="T:System.Array"/> of the specified <see cref="T:System.Type"/> and length, with zero-based indexing.
    /// </summary>
    /// 
    /// <returns>
    /// A new one-dimensional <see cref="T:System.Array"/> of the specified <see cref="T:System.Type"/> with the specified length, using zero-based indexing.
    /// </returns>
    /// <param name="elementType">The <see cref="T:System.Type"/> of the <see cref="T:System.Array"/> to create.</param><param name="length">The size of the <see cref="T:System.Array"/> to create.</param><exception cref="T:System.ArgumentNullException"><paramref name="elementType"/> is null.</exception><exception cref="T:System.ArgumentException"><paramref name="elementType"/> is not a valid <see cref="T:System.Type"/>.</exception><exception cref="T:System.NotSupportedException"><paramref name="elementType"/> is not supported. For example, <see cref="T:System.Void"/> is not supported.-or-<paramref name="elementType"/> is an open generic type.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="length"/> is less than zero.</exception>
    [SecuritySafeCritical]
    public static unsafe Array CreateInstance(Type elementType, int length)
    {
      if (elementType == null)
        throw new ArgumentNullException("elementType");
      if (length < 0)
        throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      RuntimeType runtimeType = elementType.UnderlyingSystemType as RuntimeType;
      if (runtimeType == null)
        throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
      else
        return Array.InternalCreate((void*) runtimeType.TypeHandle.Value, 1, &length, (int*) null);
    }

    /// <summary>
    /// Creates a multidimensional <see cref="T:System.Array"/> of the specified <see cref="T:System.Type"/> and dimension lengths, with zero-based indexing. The dimension lengths are specified in an array of 32-bit integers.
    /// </summary>
    /// 
    /// <returns>
    /// A new multidimensional <see cref="T:System.Array"/> of the specified <see cref="T:System.Type"/> with the specified length for each dimension, using zero-based indexing.
    /// </returns>
    /// <param name="elementType">The <see cref="T:System.Type"/> of the <see cref="T:System.Array"/> to create.</param><param name="lengths">An array of 32-bit integers that represent the size of each dimension of the <see cref="T:System.Array"/> to create.</param><exception cref="T:System.ArgumentNullException"><paramref name="elementType"/> is null.-or-<paramref name="lengths"/> is null.</exception><exception cref="T:System.ArgumentException"><paramref name="elementType"/> is not a valid <see cref="T:System.Type"/>.-or-The <paramref name="lengths"/> array contains less than one element.</exception><exception cref="T:System.NotSupportedException"><paramref name="elementType"/> is not supported. For example, <see cref="T:System.Void"/> is not supported. -or-<paramref name="elementType"/> is an open generic type.</exception><exception cref="T:System.ArgumentOutOfRangeException">Any value in <paramref name="lengths"/> is less than zero.</exception>
    [SecuritySafeCritical]
    public static unsafe Array CreateInstance(Type elementType, params int[] lengths)
    {
      if (elementType == null)
        throw new ArgumentNullException("elementType");
      if (lengths == null)
        throw new ArgumentNullException("lengths");
      if (lengths.Length == 0)
        throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank"));
      RuntimeType runtimeType = elementType.UnderlyingSystemType as RuntimeType;
      if (runtimeType == null)
        throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
      for (int index = 0; index < lengths.Length; ++index)
      {
        if (lengths[index] < 0)
          throw new ArgumentOutOfRangeException("lengths[" + (object) index + (string) (object) ']', Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      }
      fixed (int* pLengths = lengths)
        return Array.InternalCreate((void*) runtimeType.TypeHandle.Value, lengths.Length, pLengths, (int*) null);
    }

    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static Array InternalCreate(void* elementType, int rank, int* pLengths, int* pLowerBounds);

    [SecurityCritical]
    internal static Array UnsafeCreateInstance(Type elementType, int length)
    {
      return Array.CreateInstance(elementType, length);
    }

    /// <summary>
    /// Copies a range of elements from an <see cref="T:System.Array"/> starting at the first element and pastes them into another <see cref="T:System.Array"/> starting at the first element. The length is specified as a 32-bit integer.
    /// </summary>
    /// <param name="sourceArray">The <see cref="T:System.Array"/> that contains the data to copy.</param><param name="destinationArray">The <see cref="T:System.Array"/> that receives the data.</param><param name="length">A 32-bit integer that represents the number of elements to copy.</param><exception cref="T:System.ArgumentNullException"><paramref name="sourceArray"/> is null.-or-<paramref name="destinationArray"/> is null.</exception><exception cref="T:System.RankException"><paramref name="sourceArray"/> and <paramref name="destinationArray"/> have different ranks.</exception><exception cref="T:System.ArrayTypeMismatchException"><paramref name="sourceArray"/> and <paramref name="destinationArray"/> are of incompatible types.</exception><exception cref="T:System.InvalidCastException">At least one element in <paramref name="sourceArray"/> cannot be cast to the type of <paramref name="destinationArray"/>.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="length"/> is greater than the number of elements in <paramref name="sourceArray"/>.-or-<paramref name="length"/> is greater than the number of elements in <paramref name="destinationArray"/>.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    [SecuritySafeCritical]
    public static void Copy(Array sourceArray, Array destinationArray, int length)
    {
      if (sourceArray == null)
        throw new ArgumentNullException("sourceArray");
      if (destinationArray == null)
        throw new ArgumentNullException("destinationArray");
      Array.Copy(sourceArray, sourceArray.GetLowerBound(0), destinationArray, destinationArray.GetLowerBound(0), length, false);
    }

    /// <summary>
    /// Copies a range of elements from an <see cref="T:System.Array"/> starting at the specified source index and pastes them to another <see cref="T:System.Array"/> starting at the specified destination index. The length and the indexes are specified as 32-bit integers.
    /// </summary>
    /// <param name="sourceArray">The <see cref="T:System.Array"/> that contains the data to copy.</param><param name="sourceIndex">A 32-bit integer that represents the index in the <paramref name="sourceArray"/> at which copying begins.</param><param name="destinationArray">The <see cref="T:System.Array"/> that receives the data.</param><param name="destinationIndex">A 32-bit integer that represents the index in the <paramref name="destinationArray"/> at which storing begins.</param><param name="length">A 32-bit integer that represents the number of elements to copy.</param><exception cref="T:System.ArgumentNullException"><paramref name="sourceArray"/> is null.-or-<paramref name="destinationArray"/> is null.</exception><exception cref="T:System.RankException"><paramref name="sourceArray"/> and <paramref name="destinationArray"/> have different ranks.</exception><exception cref="T:System.ArrayTypeMismatchException"><paramref name="sourceArray"/> and <paramref name="destinationArray"/> are of incompatible types.</exception><exception cref="T:System.InvalidCastException">At least one element in <paramref name="sourceArray"/> cannot be cast to the type of <paramref name="destinationArray"/>.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="sourceIndex"/> is less than the lower bound of the first dimension of <paramref name="sourceArray"/>.-or-<paramref name="destinationIndex"/> is less than the lower bound of the first dimension of <paramref name="destinationArray"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="length"/> is greater than the number of elements from <paramref name="sourceIndex"/> to the end of <paramref name="sourceArray"/>.-or-<paramref name="length"/> is greater than the number of elements from <paramref name="destinationIndex"/> to the end of <paramref name="destinationArray"/>.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
    {
      Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, false);
    }

    [SecurityCritical]
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable);

    /// <summary>
    /// Copies a range of elements from an <see cref="T:System.Array"/> starting at the specified source index and pastes them to another <see cref="T:System.Array"/> starting at the specified destination index.  Guarantees that all changes are undone if the copy does not succeed completely.
    /// </summary>
    /// <param name="sourceArray">The <see cref="T:System.Array"/> that contains the data to copy.</param><param name="sourceIndex">A 32-bit integer that represents the index in the <paramref name="sourceArray"/> at which copying begins.</param><param name="destinationArray">The <see cref="T:System.Array"/> that receives the data.</param><param name="destinationIndex">A 32-bit integer that represents the index in the <paramref name="destinationArray"/> at which storing begins.</param><param name="length">A 32-bit integer that represents the number of elements to copy.</param><exception cref="T:System.ArgumentNullException"><paramref name="sourceArray"/> is null.-or-<paramref name="destinationArray"/> is null.</exception><exception cref="T:System.RankException"><paramref name="sourceArray"/> and <paramref name="destinationArray"/> have different ranks.</exception><exception cref="T:System.ArrayTypeMismatchException">The <paramref name="sourceArray"/> type is neither the same as nor derived from the <paramref name="destinationArray"/> type.</exception><exception cref="T:System.InvalidCastException">At least one element in <paramref name="sourceArray"/> cannot be cast to the type of <paramref name="destinationArray"/>.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="sourceIndex"/> is less than the lower bound of the first dimension of <paramref name="sourceArray"/>.-or-<paramref name="destinationIndex"/> is less than the lower bound of the first dimension of <paramref name="destinationArray"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="length"/> is greater than the number of elements from <paramref name="sourceIndex"/> to the end of <paramref name="sourceArray"/>.-or-<paramref name="length"/> is greater than the number of elements from <paramref name="destinationIndex"/> to the end of <paramref name="destinationArray"/>.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    public static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
    {
      Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, true);
    }

    /// <summary>
    /// Sets a range of elements in the <see cref="T:System.Array"/> to zero, to false, or to null, depending on the element type.
    /// </summary>
    /// <param name="array">The <see cref="T:System.Array"/> whose elements need to be cleared.</param><param name="index">The starting index of the range of elements to clear.</param><param name="length">The number of elements to clear.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.IndexOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.-or-The sum of <paramref name="index"/> and <paramref name="length"/> is greater than the size of the <see cref="T:System.Array"/>.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static void Clear(Array array, int index, int length);

    /// <summary>
    /// Gets the value at the specified position in the multidimensional <see cref="T:System.Array"/>. The indexes are specified as an array of 32-bit integers.
    /// </summary>
    /// 
    /// <returns>
    /// The value at the specified position in the multidimensional <see cref="T:System.Array"/>.
    /// </returns>
    /// <param name="indices">A one-dimensional array of 32-bit integers that represent the indexes specifying the position of the <see cref="T:System.Array"/> element to get.</param><exception cref="T:System.ArgumentNullException"><paramref name="indices"/> is null.</exception><exception cref="T:System.ArgumentException">The number of dimensions in the current <see cref="T:System.Array"/> is not equal to the number of elements in <paramref name="indices"/>.</exception><exception cref="T:System.IndexOutOfRangeException">Any element in <paramref name="indices"/> is outside the range of valid indexes for the corresponding dimension of the current <see cref="T:System.Array"/>.</exception>
    [SecuritySafeCritical]
    public unsafe object GetValue(params int[] indices)
    {
      if (indices == null)
        throw new ArgumentNullException("indices");
      if (this.Rank != indices.Length)
        throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
      TypedReference typedReference = new TypedReference();
      fixed (int* pIndices = indices)
        this.InternalGetReference((void*) &typedReference, indices.Length, pIndices);
      return TypedReference.InternalToObject((void*) &typedReference);
    }

    /// <summary>
    /// Gets the value at the specified position in the one-dimensional <see cref="T:System.Array"/>. The index is specified as a 32-bit integer.
    /// </summary>
    /// 
    /// <returns>
    /// The value at the specified position in the one-dimensional <see cref="T:System.Array"/>.
    /// </returns>
    /// <param name="index">A 32-bit integer that represents the position of the <see cref="T:System.Array"/> element to get.</param><exception cref="T:System.ArgumentException">The current <see cref="T:System.Array"/> does not have exactly one dimension.</exception><exception cref="T:System.IndexOutOfRangeException"><paramref name="index"/> is outside the range of valid indexes for the current <see cref="T:System.Array"/>.</exception>
    [SecuritySafeCritical]
    public unsafe object GetValue(int index)
    {
      if (this.Rank != 1)
        throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray"));
      TypedReference typedReference = new TypedReference();
      this.InternalGetReference((void*) &typedReference, 1, &index);
      return TypedReference.InternalToObject((void*) &typedReference);
    }

    /// <summary>
    /// Sets a value to the element at the specified position in the one-dimensional <see cref="T:System.Array"/>. The index is specified as a 32-bit integer.
    /// </summary>
    /// <param name="value">The new value for the specified element.</param><param name="index">A 32-bit integer that represents the position of the <see cref="T:System.Array"/> element to set.</param><exception cref="T:System.ArgumentException">The current <see cref="T:System.Array"/> does not have exactly one dimension.</exception><exception cref="T:System.InvalidCastException"><paramref name="value"/> cannot be cast to the element type of the current <see cref="T:System.Array"/>.</exception><exception cref="T:System.IndexOutOfRangeException"><paramref name="index"/> is outside the range of valid indexes for the current <see cref="T:System.Array"/>.</exception>
    [SecuritySafeCritical]
    public unsafe void SetValue(object value, int index)
    {
      if (this.Rank != 1)
        throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray"));
      TypedReference typedReference = new TypedReference();
      this.InternalGetReference((void*) &typedReference, 1, &index);
      Array.InternalSetValue((void*) &typedReference, value);
    }

    /// <summary>
    /// Sets a value to the element at the specified position in the multidimensional <see cref="T:System.Array"/>. The indexes are specified as an array of 32-bit integers.
    /// </summary>
    /// <param name="value">The new value for the specified element.</param><param name="indices">A one-dimensional array of 32-bit integers that represent the indexes specifying the position of the element to set.</param><exception cref="T:System.ArgumentNullException"><paramref name="indices"/> is null.</exception><exception cref="T:System.ArgumentException">The number of dimensions in the current <see cref="T:System.Array"/> is not equal to the number of elements in <paramref name="indices"/>.</exception><exception cref="T:System.InvalidCastException"><paramref name="value"/> cannot be cast to the element type of the current <see cref="T:System.Array"/>.</exception><exception cref="T:System.IndexOutOfRangeException">Any element in <paramref name="indices"/> is outside the range of valid indexes for the corresponding dimension of the current <see cref="T:System.Array"/>.</exception>
    [SecuritySafeCritical]
    public unsafe void SetValue(object value, params int[] indices)
    {
      if (indices == null)
        throw new ArgumentNullException("indices");
      if (this.Rank != indices.Length)
        throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
      TypedReference typedReference = new TypedReference();
      fixed (int* pIndices = indices)
        this.InternalGetReference((void*) &typedReference, indices.Length, pIndices);
      Array.InternalSetValue((void*) &typedReference, value);
    }

    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private void InternalGetReference(void* elemRef, int rank, int* pIndices);

    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static void InternalSetValue(void* target, object value);

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    private static int GetMedian(int low, int hi)
    {
      return low + (hi - low >> 1);
    }

    /// <summary>
    /// Gets a 32-bit integer that represents the number of elements in the specified dimension of the <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// A 32-bit integer that represents the number of elements in the specified dimension.
    /// </returns>
    /// <param name="dimension">A zero-based dimension of the <see cref="T:System.Array"/> whose length needs to be determined.</param><exception cref="T:System.IndexOutOfRangeException"><paramref name="dimension"/> is less than zero.-or-<paramref name="dimension"/> is equal to or greater than <see cref="P:System.Array.Rank"/>.</exception>
    [SecuritySafeCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public int GetLength(int dimension);

    /// <summary>
    /// Gets the upper bound of the specified dimension in the <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// The upper bound of the specified dimension in the <see cref="T:System.Array"/>.
    /// </returns>
    /// <param name="dimension">A zero-based dimension of the <see cref="T:System.Array"/> whose upper bound needs to be determined.</param><exception cref="T:System.IndexOutOfRangeException"><paramref name="dimension"/> is less than zero.-or-<paramref name="dimension"/> is equal to or greater than <see cref="P:System.Array.Rank"/>.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public int GetUpperBound(int dimension);

    /// <summary>
    /// Gets the lower bound of the specified dimension in the <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// The lower bound of the specified dimension in the <see cref="T:System.Array"/>.
    /// </returns>
    /// <param name="dimension">A zero-based dimension of the <see cref="T:System.Array"/> whose lower bound needs to be determined.</param><exception cref="T:System.IndexOutOfRangeException"><paramref name="dimension"/> is less than zero.-or-<paramref name="dimension"/> is equal to or greater than <see cref="P:System.Array.Rank"/>.</exception>
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    [SecuritySafeCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public int GetLowerBound(int dimension);

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal int GetDataPtrOffsetInternal();

    object IList.get_Item(int index)
    {
      return this.GetValue(index);
    }

    void IList.set_Item(int index, object value)
    {
      this.SetValue(value, index);
    }

    int IList.Add(object value)
    {
      throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
    }

    bool IList.Contains(object value)
    {
      return Array.IndexOf(this, value) >= this.GetLowerBound(0);
    }

    void IList.Clear()
    {
      Array.Clear(this, this.GetLowerBound(0), this.Length);
    }

    int IList.IndexOf(object value)
    {
      return Array.IndexOf(this, value);
    }

    void IList.Insert(int index, object value)
    {
      throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
    }

    void IList.Remove(object value)
    {
      throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
    }

    void IList.RemoveAt(int index)
    {
      throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
    }

    /// <summary>
    /// Creates a shallow copy of the <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// A shallow copy of the <see cref="T:System.Array"/>.
    /// </returns>
    public object Clone()
    {
      return this.MemberwiseClone();
    }

    int IStructuralComparable.CompareTo(object other, IComparer comparer)
    {
      if (other == null)
        return 1;
      Array array = other as Array;
      if (array == null || this.Length != array.Length)
        throw new ArgumentException(Environment.GetResourceString("ArgumentException_OtherNotArrayOfCorrectLength"), "other");
      int index = 0;
      int num;
      for (num = 0; index < array.Length && num == 0; ++index)
      {
        object x = this.GetValue(index);
        object y = array.GetValue(index);
        num = comparer.Compare(x, y);
      }
      return num;
    }

    bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
    {
      if (other == null)
        return false;
      if (object.ReferenceEquals((object) this, other))
        return true;
      Array array = other as Array;
      if (array == null || array.Length != this.Length)
        return false;
      for (int index = 0; index < array.Length; ++index)
      {
        object x = this.GetValue(index);
        object y = array.GetValue(index);
        if (!comparer.Equals(x, y))
          return false;
      }
      return true;
    }

    internal static int CombineHashCodes(int h1, int h2)
    {
      return (h1 << 5) + h1 ^ h2;
    }

    int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
    {
      if (comparer == null)
        throw new ArgumentNullException("comparer");
      int h1 = 0;
      for (int index = this.Length >= 8 ? this.Length - 8 : 0; index < this.Length; ++index)
        h1 = Array.CombineHashCodes(h1, comparer.GetHashCode(this.GetValue(0)));
      return h1;
    }

    /// <summary>
    /// Searches an entire one-dimensional sorted <see cref="T:System.Array"/> for a specific element, using the <see cref="T:System.IComparable"/> interface implemented by each element of the <see cref="T:System.Array"/> and by the specified object.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the specified <paramref name="value"/> in the specified <paramref name="array"/>, if <paramref name="value"/> is found. If <paramref name="value"/> is not found and <paramref name="value"/> is less than one or more elements in <paramref name="array"/>, a negative number which is the bitwise complement of the index of the first element that is larger than <paramref name="value"/>. If <paramref name="value"/> is not found and <paramref name="value"/> is greater than any of the elements in <paramref name="array"/>, a negative number which is the bitwise complement of (the index of the last element plus 1).
    /// </returns>
    /// <param name="array">The sorted one-dimensional <see cref="T:System.Array"/> to search.</param><param name="value">The object to search for.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception><exception cref="T:System.ArgumentException"><paramref name="value"/> is of a type that is not compatible with the elements of <paramref name="array"/>.</exception><exception cref="T:System.InvalidOperationException"><paramref name="value"/> does not implement the <see cref="T:System.IComparable"/> interface, and the search encounters an element that does not implement the <see cref="T:System.IComparable"/> interface.</exception>
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int BinarySearch(Array array, object value)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      int lowerBound = array.GetLowerBound(0);
      return Array.BinarySearch(array, lowerBound, array.Length, value, (IComparer) null);
    }

    /// <summary>
    /// Searches a range of elements in a one-dimensional sorted <see cref="T:System.Array"/> for a value, using the specified <see cref="T:System.Collections.IComparer"/> interface.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the specified <paramref name="value"/> in the specified <paramref name="array"/>, if <paramref name="value"/> is found. If <paramref name="value"/> is not found and <paramref name="value"/> is less than one or more elements in <paramref name="array"/>, a negative number which is the bitwise complement of the index of the first element that is larger than <paramref name="value"/>. If <paramref name="value"/> is not found and <paramref name="value"/> is greater than any of the elements in <paramref name="array"/>, a negative number which is the bitwise complement of (the index of the last element plus 1).
    /// </returns>
    /// <param name="array">The sorted one-dimensional <see cref="T:System.Array"/> to search.</param><param name="index">The starting index of the range to search.</param><param name="length">The length of the range to search.</param><param name="value">The object to search for.</param><param name="comparer">The <see cref="T:System.Collections.IComparer"/> implementation to use when comparing elements.-or- null to use the <see cref="T:System.IComparable"/> implementation of each element.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="index"/> and <paramref name="length"/> do not specify a valid range in <paramref name="array"/>.-or-<paramref name="comparer"/> is null, and <paramref name="value"/> is of a type that is not compatible with the elements of <paramref name="array"/>.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, <paramref name="value"/> does not implement the <see cref="T:System.IComparable"/> interface, and the search encounters an element that does not implement the <see cref="T:System.IComparable"/> interface.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int BinarySearch(Array array, int index, int length, object value, IComparer comparer)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      int lowerBound = array.GetLowerBound(0);
      if (index < lowerBound || length < 0)
        throw new ArgumentOutOfRangeException(index < lowerBound ? "index" : "length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      if (array.Length - (index - lowerBound) < length)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
      if (array.Rank != 1)
        throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
      if (comparer == null)
        comparer = (IComparer) Comparer.Default;
      int retVal;
      if (comparer == Comparer.Default && Array.TrySZBinarySearch(array, index, length, value, out retVal))
        return retVal;
      int low = index;
      int hi = index + length - 1;
      object[] objArray = array as object[];
      if (objArray != null)
      {
        while (low <= hi)
        {
          int median = Array.GetMedian(low, hi);
          int num;
          try
          {
            num = comparer.Compare(objArray[median], value);
          }
          catch (Exception ex)
          {
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
          }
          if (num == 0)
            return median;
          if (num < 0)
            low = median + 1;
          else
            hi = median - 1;
        }
      }
      else
      {
        while (low <= hi)
        {
          int median = Array.GetMedian(low, hi);
          int num;
          try
          {
            num = comparer.Compare(array.GetValue(median), value);
          }
          catch (Exception ex)
          {
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
          }
          if (num == 0)
            return median;
          if (num < 0)
            low = median + 1;
          else
            hi = median - 1;
        }
      }
      return ~low;
    }

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static bool TrySZBinarySearch(Array sourceArray, int sourceIndex, int count, object value, out int retVal);

    /// <summary>
    /// Searches an entire one-dimensional sorted <see cref="T:System.Array"/> for a specific element, using the <see cref="T:System.IComparable`1"/> generic interface implemented by each element of the <see cref="T:System.Array"/> and by the specified object.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the specified <paramref name="value"/> in the specified <paramref name="array"/>, if <paramref name="value"/> is found. If <paramref name="value"/> is not found and <paramref name="value"/> is less than one or more elements in <paramref name="array"/>, a negative number which is the bitwise complement of the index of the first element that is larger than <paramref name="value"/>. If <paramref name="value"/> is not found and <paramref name="value"/> is greater than any of the elements in <paramref name="array"/>, a negative number which is the bitwise complement of (the index of the last element plus 1).
    /// </returns>
    /// <param name="array">The sorted one-dimensional, zero-based <see cref="T:System.Array"/> to search. </param><param name="value">The object to search for.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.InvalidOperationException"><paramref name="value"/> does not implement the <see cref="T:System.IComparable`1"/> generic interface, and the search encounters an element that does not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int BinarySearch<T>(T[] array, T value)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      else
        return Array.BinarySearch<T>(array, 0, array.Length, value, (IComparer<T>) null);
    }

    /// <summary>
    /// Searches an entire one-dimensional sorted <see cref="T:System.Array"/> for a value using the specified <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the specified <paramref name="value"/> in the specified <paramref name="array"/>, if <paramref name="value"/> is found. If <paramref name="value"/> is not found and <paramref name="value"/> is less than one or more elements in <paramref name="array"/>, a negative number which is the bitwise complement of the index of the first element that is larger than <paramref name="value"/>. If <paramref name="value"/> is not found and <paramref name="value"/> is greater than any of the elements in <paramref name="array"/>, a negative number which is the bitwise complement of (the index of the last element plus 1).
    /// </returns>
    /// <param name="array">The sorted one-dimensional, zero-based <see cref="T:System.Array"/> to search.  </param><param name="value">The object to search for.</param><param name="comparer">The <see cref="T:System.Collections.Generic.IComparer`1"/> implementation to use when comparing elements.-or- null to use the <see cref="T:System.IComparable`1"/> implementation of each element.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentException"><paramref name="comparer"/> is null, and <paramref name="value"/> is of a type that is not compatible with the elements of <paramref name="array"/>.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, <paramref name="value"/> does not implement the <see cref="T:System.IComparable`1"/> generic interface, and the search encounters an element that does not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int BinarySearch<T>(T[] array, T value, IComparer<T> comparer)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      else
        return Array.BinarySearch<T>(array, 0, array.Length, value, comparer);
    }

    /// <summary>
    /// Searches a range of elements in a one-dimensional sorted <see cref="T:System.Array"/> for a value, using the <see cref="T:System.IComparable`1"/> generic interface implemented by each element of the <see cref="T:System.Array"/> and by the specified value.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the specified <paramref name="value"/> in the specified <paramref name="array"/>, if <paramref name="value"/> is found. If <paramref name="value"/> is not found and <paramref name="value"/> is less than one or more elements in <paramref name="array"/>, a negative number which is the bitwise complement of the index of the first element that is larger than <paramref name="value"/>. If <paramref name="value"/> is not found and <paramref name="value"/> is greater than any of the elements in <paramref name="array"/>, a negative number which is the bitwise complement of (the index of the last element plus 1).
    /// </returns>
    /// <param name="array">The sorted one-dimensional, zero-based <see cref="T:System.Array"/> to search. </param><param name="index">The starting index of the range to search.</param><param name="length">The length of the range to search.</param><param name="value">The object to search for.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="index"/> and <paramref name="length"/> do not specify a valid range in <paramref name="array"/>.-or-<paramref name="value"/> is of a type that is not compatible with the elements of <paramref name="array"/>.</exception><exception cref="T:System.InvalidOperationException"><paramref name="value"/> does not implement the <see cref="T:System.IComparable`1"/> generic interface, and the search encounters an element that does not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int BinarySearch<T>(T[] array, int index, int length, T value)
    {
      return Array.BinarySearch<T>(array, index, length, value, (IComparer<T>) null);
    }

    /// <summary>
    /// Searches a range of elements in a one-dimensional sorted <see cref="T:System.Array"/> for a value, using the specified <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the specified <paramref name="value"/> in the specified <paramref name="array"/>, if <paramref name="value"/> is found. If <paramref name="value"/> is not found and <paramref name="value"/> is less than one or more elements in <paramref name="array"/>, a negative number which is the bitwise complement of the index of the first element that is larger than <paramref name="value"/>. If <paramref name="value"/> is not found and <paramref name="value"/> is greater than any of the elements in <paramref name="array"/>, a negative number which is the bitwise complement of (the index of the last element plus 1).
    /// </returns>
    /// <param name="array">The sorted one-dimensional, zero-based <see cref="T:System.Array"/> to search. </param><param name="index">The starting index of the range to search.</param><param name="length">The length of the range to search.</param><param name="value">The object to search for.</param><param name="comparer">The <see cref="T:System.Collections.Generic.IComparer`1"/> implementation to use when comparing elements.-or- null to use the <see cref="T:System.IComparable`1"/> implementation of each element.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="index"/> and <paramref name="length"/> do not specify a valid range in <paramref name="array"/>.-or-<paramref name="comparer"/> is null, and <paramref name="value"/> is of a type that is not compatible with the elements of <paramref name="array"/>.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, <paramref name="value"/> does not implement the <see cref="T:System.IComparable`1"/> generic interface, and the search encounters an element that does not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int BinarySearch<T>(T[] array, int index, int length, T value, IComparer<T> comparer)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (index < 0 || length < 0)
        throw new ArgumentOutOfRangeException(index < 0 ? "index" : "length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      if (array.Length - index < length)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
      else
        return ArraySortHelper<T>.Default.BinarySearch(array, index, length, value, comparer);
    }

    /// <summary>
    /// Copies all the elements of the current one-dimensional <see cref="T:System.Array"/> to the specified one-dimensional <see cref="T:System.Array"/> starting at the specified destination <see cref="T:System.Array"/> index. The index is specified as a 32-bit integer.
    /// </summary>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from the current <see cref="T:System.Array"/>.</param><param name="index">A 32-bit integer that represents the index in <paramref name="array"/> at which copying begins.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.</exception><exception cref="T:System.ArgumentException"><paramref name="array"/> is multidimensional.-or-The number of elements in the source <see cref="T:System.Array"/> is greater than the available space from <paramref name="index"/> to the end of the destination <paramref name="array"/>.</exception><exception cref="T:System.ArrayTypeMismatchException">The type of the source <see cref="T:System.Array"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.</exception><exception cref="T:System.RankException">The source <see cref="T:System.Array"/> is multidimensional.</exception><exception cref="T:System.InvalidCastException">At least one element in the source <see cref="T:System.Array"/> cannot be cast to the type of destination <paramref name="array"/>.</exception>
    public void CopyTo(Array array, int index)
    {
      if (array != null && array.Rank != 1)
        throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported"));
      Array.Copy(this, this.GetLowerBound(0), array, index, this.Length);
    }

    /// <summary>
    /// Performs the specified action on each element of the specified array.
    /// </summary>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> on whose elements the action is to be performed.</param><param name="action">The <see cref="T:System.Action`1"/> to perform on each element of <paramref name="array"/>.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.-or-<paramref name="action"/> is null.</exception>
    public static void ForEach<T>(T[] array, Action<T> action)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (action == null)
        throw new ArgumentNullException("action");
      for (int index = 0; index < array.Length; ++index)
        action(array[index]);
    }

    /// <summary>
    /// Returns an <see cref="T:System.Collections.IEnumerator"/> for the <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// An <see cref="T:System.Collections.IEnumerator"/> for the <see cref="T:System.Array"/>.
    /// </returns>
    public IEnumerator GetEnumerator()
    {
      int lowerBound = this.GetLowerBound(0);
      if (this.Rank == 1 && lowerBound == 0)
        return (IEnumerator) new Array.SZArrayEnumerator(this);
      else
        return (IEnumerator) new Array.ArrayEnumerator(this, lowerBound, this.Length);
    }

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    internal static int IndexOf(Array array, object value)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      int lowerBound = array.GetLowerBound(0);
      return Array.IndexOf(array, value, lowerBound, array.Length);
    }

    /// <summary>
    /// Searches for the specified object and returns the index of the first occurrence within the range of elements in the one-dimensional <see cref="T:System.Array"/> that starts at the specified index and contains the specified number of elements.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the first occurrence of <paramref name="value"/> within the range of elements in <paramref name="array"/> that starts at <paramref name="startIndex"/> and contains the number of elements specified in <paramref name="count"/>, if found; otherwise, the lower bound of the array minus 1.
    /// </returns>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><param name="startIndex">The starting index of the search.</param><param name="count">The number of elements in the section to search.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="startIndex"/> is outside the range of valid indexes for <paramref name="array"/>.-or-<paramref name="count"/> is less than zero.-or-<paramref name="startIndex"/> and <paramref name="count"/> do not specify a valid section in <paramref name="array"/>.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int IndexOf(Array array, object value, int startIndex, int count)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (array.Rank != 1)
        throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
      int lowerBound = array.GetLowerBound(0);
      if (startIndex < lowerBound || startIndex > array.Length + lowerBound)
        throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
      if (count < 0 || count > array.Length - startIndex + lowerBound)
        throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
      int retVal;
      if (Array.TrySZIndexOf(array, startIndex, count, value, out retVal))
        return retVal;
      object[] objArray = array as object[];
      int num = startIndex + count;
      if (objArray != null)
      {
        if (value == null)
        {
          for (int index = startIndex; index < num; ++index)
          {
            if (objArray[index] == null)
              return index;
          }
        }
        else
        {
          for (int index = startIndex; index < num; ++index)
          {
            object obj = objArray[index];
            if (obj != null && obj.Equals(value))
              return index;
          }
        }
      }
      else
      {
        for (int index = startIndex; index < num; ++index)
        {
          object obj = array.GetValue(index);
          if (obj == null)
          {
            if (value == null)
              return index;
          }
          else if (obj.Equals(value))
            return index;
        }
      }
      return lowerBound - 1;
    }

    /// <summary>
    /// Searches for the specified object and returns the index of the first occurrence within the entire <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// The zero-based index of the first occurrence of <paramref name="value"/> within the entire <paramref name="array"/>, if found; otherwise, –1.
    /// </returns>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception>
    public static int IndexOf<T>(T[] array, T value)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      else
        return Array.IndexOf<T>(array, value, 0, array.Length);
    }

    /// <summary>
    /// Searches for the specified object and returns the index of the first occurrence within the range of elements in the <see cref="T:System.Array"/> that extends from the specified index to the last element.
    /// </summary>
    /// 
    /// <returns>
    /// The zero-based index of the first occurrence of <paramref name="value"/> within the range of elements in <paramref name="array"/> that extends from <paramref name="startIndex"/> to the last element, if found; otherwise, –1.
    /// </returns>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><param name="startIndex">The zero-based starting index of the search.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="startIndex"/> is outside the range of valid indexes for <paramref name="array"/>.</exception>
    public static int IndexOf<T>(T[] array, T value, int startIndex)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      else
        return Array.IndexOf<T>(array, value, startIndex, array.Length - startIndex);
    }

    /// <summary>
    /// Searches for the specified object and returns the index of the first occurrence within the range of elements in the <see cref="T:System.Array"/> that starts at the specified index and contains the specified number of elements.
    /// </summary>
    /// 
    /// <returns>
    /// The zero-based index of the first occurrence of <paramref name="value"/> within the range of elements in <paramref name="array"/> that starts at <paramref name="startIndex"/> and contains the number of elements specified in <paramref name="count"/>, if found; otherwise, –1.
    /// </returns>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><param name="startIndex">The zero-based starting index of the search.</param><param name="count">The number of elements in the section to search.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="startIndex"/> is outside the range of valid indexes for <paramref name="array"/>.-or-<paramref name="count"/> is less than zero.-or-<paramref name="startIndex"/> and <paramref name="count"/> do not specify a valid section in <paramref name="array"/>.</exception>
    public static int IndexOf<T>(T[] array, T value, int startIndex, int count)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (startIndex < 0 || startIndex > array.Length)
        throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
      if (count < 0 || count > array.Length - startIndex)
        throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
      else
        return EqualityComparer<T>.Default.IndexOf(array, value, startIndex, count);
    }

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static bool TrySZIndexOf(Array sourceArray, int sourceIndex, int count, object value, out int retVal);

    /// <summary>
    /// Searches for the specified object and returns the index of the last occurrence within the range of elements in the one-dimensional <see cref="T:System.Array"/> that contains the specified number of elements and ends at the specified index.
    /// </summary>
    /// 
    /// <returns>
    /// The index of the last occurrence of <paramref name="value"/> within the range of elements in <paramref name="array"/> that contains the number of elements specified in <paramref name="count"/> and ends at <paramref name="startIndex"/>, if found; otherwise, the lower bound of the array minus 1.
    /// </returns>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><param name="startIndex">The starting index of the backward search.</param><param name="count">The number of elements in the section to search.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="startIndex"/> is outside the range of valid indexes for <paramref name="array"/>.-or-<paramref name="count"/> is less than zero.-or-<paramref name="startIndex"/> and <paramref name="count"/> do not specify a valid section in <paramref name="array"/>.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public static int LastIndexOf(Array array, object value, int startIndex, int count)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      int lowerBound = array.GetLowerBound(0);
      if (array.Length == 0)
        return lowerBound - 1;
      if (startIndex < lowerBound || startIndex >= array.Length + lowerBound)
        throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
      if (count < 0)
        throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
      if (count > startIndex - lowerBound + 1)
        throw new ArgumentOutOfRangeException("endIndex", Environment.GetResourceString("ArgumentOutOfRange_EndIndexStartIndex"));
      if (array.Rank != 1)
        throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
      int retVal;
      if (Array.TrySZLastIndexOf(array, startIndex, count, value, out retVal))
        return retVal;
      object[] objArray = array as object[];
      int num = startIndex - count + 1;
      if (objArray != null)
      {
        if (value == null)
        {
          for (int index = startIndex; index >= num; --index)
          {
            if (objArray[index] == null)
              return index;
          }
        }
        else
        {
          for (int index = startIndex; index >= num; --index)
          {
            object obj = objArray[index];
            if (obj != null && obj.Equals(value))
              return index;
          }
        }
      }
      else
      {
        for (int index = startIndex; index >= num; --index)
        {
          object obj = array.GetValue(index);
          if (obj == null)
          {
            if (value == null)
              return index;
          }
          else if (obj.Equals(value))
            return index;
        }
      }
      return lowerBound - 1;
    }

    /// <summary>
    /// Searches for the specified object and returns the index of the last occurrence within the entire <see cref="T:System.Array"/>.
    /// </summary>
    /// 
    /// <returns>
    /// The zero-based index of the last occurrence of <paramref name="value"/> within the entire <paramref name="array"/>, if found; otherwise, –1.
    /// </returns>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception>
    public static int LastIndexOf<T>(T[] array, T value)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      else
        return Array.LastIndexOf<T>(array, value, array.Length - 1, array.Length);
    }

    /// <summary>
    /// Searches for the specified object and returns the index of the last occurrence within the range of elements in the <see cref="T:System.Array"/> that extends from the first element to the specified index.
    /// </summary>
    /// 
    /// <returns>
    /// The zero-based index of the last occurrence of <paramref name="value"/> within the range of elements in <paramref name="array"/> that extends from the first element to <paramref name="startIndex"/>, if found; otherwise, –1.
    /// </returns>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><param name="startIndex">The zero-based starting index of the backward search.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="startIndex"/> is outside the range of valid indexes for <paramref name="array"/>.</exception>
    public static int LastIndexOf<T>(T[] array, T value, int startIndex)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      else
        return Array.LastIndexOf<T>(array, value, startIndex, array.Length == 0 ? 0 : startIndex + 1);
    }

    /// <summary>
    /// Searches for the specified object and returns the index of the last occurrence within the range of elements in the <see cref="T:System.Array"/> that contains the specified number of elements and ends at the specified index.
    /// </summary>
    /// 
    /// <returns>
    /// The zero-based index of the last occurrence of <paramref name="value"/> within the range of elements in <paramref name="array"/> that contains the number of elements specified in <paramref name="count"/> and ends at <paramref name="startIndex"/>, if found; otherwise, –1.
    /// </returns>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to search.</param><param name="value">The object to locate in <paramref name="array"/>.</param><param name="startIndex">The zero-based starting index of the backward search.</param><param name="count">The number of elements in the section to search.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="startIndex"/> is outside the range of valid indexes for <paramref name="array"/>.-or-<paramref name="count"/> is less than zero.-or-<paramref name="startIndex"/> and <paramref name="count"/> do not specify a valid section in <paramref name="array"/>.</exception>
    public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (array.Length == 0)
      {
        if (startIndex != -1 && startIndex != 0)
          throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
        if (count != 0)
          throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
        else
          return -1;
      }
      else
      {
        if (startIndex < 0 || startIndex >= array.Length)
          throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
        if (count < 0 || startIndex - count + 1 < 0)
          throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
        else
          return EqualityComparer<T>.Default.LastIndexOf(array, value, startIndex, count);
      }
    }

    [SecurityCritical]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static bool TrySZLastIndexOf(Array sourceArray, int sourceIndex, int count, object value, out int retVal);

    /// <summary>
    /// Reverses the sequence of the elements in the entire one-dimensional <see cref="T:System.Array"/>.
    /// </summary>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> to reverse.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null. </exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional. </exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Reverse(Array array)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      Array.Reverse(array, array.GetLowerBound(0), array.Length);
    }

    /// <summary>
    /// Reverses the sequence of the elements in a range of elements in the one-dimensional <see cref="T:System.Array"/>.
    /// </summary>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> to reverse.</param><param name="index">The starting index of the section to reverse.</param><param name="length">The number of elements in the section to reverse.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="index"/> and <paramref name="length"/> do not specify a valid range in <paramref name="array"/>.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    [SecuritySafeCritical]
    public static void Reverse(Array array, int index, int length)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (index < array.GetLowerBound(0) || length < 0)
        throw new ArgumentOutOfRangeException(index < 0 ? "index" : "length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      if (array.Length - (index - array.GetLowerBound(0)) < length)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
      if (array.Rank != 1)
        throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
      if (Array.TrySZReverse(array, index, length))
        return;
      int index1 = index;
      int index2 = index + length - 1;
      object[] objArray = array as object[];
      if (objArray != null)
      {
        for (; index1 < index2; --index2)
        {
          object obj = objArray[index1];
          objArray[index1] = objArray[index2];
          objArray[index2] = obj;
          ++index1;
        }
      }
      else
      {
        for (; index1 < index2; --index2)
        {
          object obj = array.GetValue(index1);
          array.SetValue(array.GetValue(index2), index1);
          array.SetValue(obj, index2);
          ++index1;
        }
      }
    }

    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static bool TrySZReverse(Array array, int index, int count);

    /// <summary>
    /// Sorts the elements in an entire one-dimensional <see cref="T:System.Array"/> using the <see cref="T:System.IComparable"/> implementation of each element of the <see cref="T:System.Array"/>.
    /// </summary>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> to sort.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception><exception cref="T:System.InvalidOperationException">One or more elements in <paramref name="array"/> do not implement the <see cref="T:System.IComparable"/> interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort(Array array)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      Array.Sort(array, (Array) null, array.GetLowerBound(0), array.Length, (IComparer) null);
    }

    /// <summary>
    /// Sorts the elements in a one-dimensional <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.IComparer"/>.
    /// </summary>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> to sort.</param><param name="comparer">The <see cref="T:System.Collections.IComparer"/> implementation to use when comparing elements.-or-null to use the <see cref="T:System.IComparable"/> implementation of each element.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in <paramref name="array"/> do not implement the <see cref="T:System.IComparable"/> interface.</exception><exception cref="T:System.ArgumentException">The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort(Array array, IComparer comparer)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      Array.Sort(array, (Array) null, array.GetLowerBound(0), array.Length, comparer);
    }

    /// <summary>
    /// Sorts a pair of one-dimensional <see cref="T:System.Array"/> objects (one contains the keys and the other contains the corresponding items) based on the keys in the first <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.IComparer"/>.
    /// </summary>
    /// <param name="keys">The one-dimensional <see cref="T:System.Array"/> that contains the keys to sort.</param><param name="items">The one-dimensional <see cref="T:System.Array"/> that contains the items that correspond to each of the keys in the <paramref name="keys"/><see cref="T:System.Array"/>.-or-null to sort only the <paramref name="keys"/><see cref="T:System.Array"/>.</param><param name="comparer">The <see cref="T:System.Collections.IComparer"/> implementation to use when comparing elements.-or-null to use the <see cref="T:System.IComparable"/> implementation of each element.</param><exception cref="T:System.ArgumentNullException"><paramref name="keys"/> is null.</exception><exception cref="T:System.RankException">The <paramref name="keys"/><see cref="T:System.Array"/> is multidimensional.-or-The <paramref name="items"/><see cref="T:System.Array"/> is multidimensional.</exception><exception cref="T:System.ArgumentException"><paramref name="items"/> is not null, and the lower bound of <paramref name="keys"/> does not match the lower bound of <paramref name="items"/>.-or-<paramref name="items"/> is not null, and the length of <paramref name="keys"/> is greater than the length of <paramref name="items"/>. -or-The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in the <paramref name="keys"/><see cref="T:System.Array"/> do not implement the <see cref="T:System.IComparable"/> interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort(Array keys, Array items, IComparer comparer)
    {
      if (keys == null)
        throw new ArgumentNullException("keys");
      Array.Sort(keys, items, keys.GetLowerBound(0), keys.Length, comparer);
    }

    /// <summary>
    /// Sorts the elements in a range of elements in a one-dimensional <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.IComparer"/>.
    /// </summary>
    /// <param name="array">The one-dimensional <see cref="T:System.Array"/> to sort.</param><param name="index">The starting index of the range to sort.</param><param name="length">The number of elements in the range to sort.</param><param name="comparer">The <see cref="T:System.Collections.IComparer"/> implementation to use when comparing elements.-or-null to use the <see cref="T:System.IComparable"/> implementation of each element.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.RankException"><paramref name="array"/> is multidimensional.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="index"/> and <paramref name="length"/> do not specify a valid range in <paramref name="array"/>. -or-The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in <paramref name="array"/> do not implement the <see cref="T:System.IComparable"/> interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort(Array array, int index, int length, IComparer comparer)
    {
      Array.Sort(array, (Array) null, index, length, comparer);
    }

    /// <summary>
    /// Sorts a range of elements in a pair of one-dimensional <see cref="T:System.Array"/> objects (one contains the keys and the other contains the corresponding items) based on the keys in the first <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.IComparer"/>.
    /// </summary>
    /// <param name="keys">The one-dimensional <see cref="T:System.Array"/> that contains the keys to sort.</param><param name="items">The one-dimensional <see cref="T:System.Array"/> that contains the items that correspond to each of the keys in the <paramref name="keys"/><see cref="T:System.Array"/>.-or-null to sort only the <paramref name="keys"/><see cref="T:System.Array"/>.</param><param name="index">The starting index of the range to sort.</param><param name="length">The number of elements in the range to sort.</param><param name="comparer">The <see cref="T:System.Collections.IComparer"/> implementation to use when comparing elements.-or-null to use the <see cref="T:System.IComparable"/> implementation of each element.</param><exception cref="T:System.ArgumentNullException"><paramref name="keys"/> is null.</exception><exception cref="T:System.RankException">The <paramref name="keys"/><see cref="T:System.Array"/> is multidimensional.-or-The <paramref name="items"/><see cref="T:System.Array"/> is multidimensional.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="keys"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="items"/> is not null, and the lower bound of <paramref name="keys"/> does not match the lower bound of <paramref name="items"/>.-or-<paramref name="items"/> is not null, and the length of <paramref name="keys"/> is greater than the length of <paramref name="items"/>.-or-<paramref name="index"/> and <paramref name="length"/> do not specify a valid range in the <paramref name="keys"/><see cref="T:System.Array"/>.-or-<paramref name="items"/> is not null, and <paramref name="index"/> and <paramref name="length"/> do not specify a valid range in the <paramref name="items"/><see cref="T:System.Array"/>. -or-The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in the <paramref name="keys"/><see cref="T:System.Array"/> do not implement the <see cref="T:System.IComparable"/> interface.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort(Array keys, Array items, int index, int length, IComparer comparer)
    {
      if (keys == null)
        throw new ArgumentNullException("keys");
      if (keys.Rank != 1 || items != null && items.Rank != 1)
        throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
      if (items != null && keys.GetLowerBound(0) != items.GetLowerBound(0))
        throw new ArgumentException(Environment.GetResourceString("Arg_LowerBoundsMustMatch"));
      if (index < keys.GetLowerBound(0) || length < 0)
        throw new ArgumentOutOfRangeException(length < 0 ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      if (keys.Length - (index - keys.GetLowerBound(0)) < length || items != null && index - items.GetLowerBound(0) > items.Length - length)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
      if (length <= 1 || (comparer == Comparer.Default || comparer == null) && Array.TrySZSort(keys, items, index, index + length - 1))
        return;
      object[] keys1 = keys as object[];
      object[] items1 = (object[]) null;
      if (keys1 != null)
        items1 = items as object[];
      if (keys1 != null && (items == null || items1 != null))
        new Array.SorterObjectArray(keys1, items1, comparer).QuickSort(index, index + length - 1);
      else
        new Array.SorterGenericArray(keys, items, comparer).QuickSort(index, index + length - 1);
    }

    [SecurityCritical]
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static bool TrySZSort(Array keys, Array items, int left, int right);

    /// <summary>
    /// Sorts the elements in an entire <see cref="T:System.Array"/> using the <see cref="T:System.IComparable`1"/> generic interface implementation of each element of the <see cref="T:System.Array"/>.
    /// </summary>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to sort.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.InvalidOperationException">One or more elements in <paramref name="array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort<T>(T[] array)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      Array.Sort<T>(array, array.GetLowerBound(0), array.Length, (IComparer<T>) null);
    }

    /// <summary>
    /// Sorts a pair of <see cref="T:System.Array"/> objects (one contains the keys and the other contains the corresponding items) based on the keys in the first <see cref="T:System.Array"/> using the <see cref="T:System.IComparable`1"/> generic interface implementation of each key.
    /// </summary>
    /// <param name="keys">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the keys to sort. </param><param name="items">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the items that correspond to the keys in <paramref name="keys"/>, or null to sort only <paramref name="keys"/>.</param><typeparam name="TKey">The type of the elements of the key array.</typeparam><typeparam name="TValue">The type of the elements of the items array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="keys"/> is null.</exception><exception cref="T:System.ArgumentException"><paramref name="items"/> is not null, and the lower bound of <paramref name="keys"/> does not match the lower bound of <paramref name="items"/>.-or-<paramref name="items"/> is not null, and the length of <paramref name="keys"/> is greater than the length of <paramref name="items"/>.</exception><exception cref="T:System.InvalidOperationException">One or more elements in the <paramref name="keys"/><see cref="T:System.Array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items)
    {
      if (keys == null)
        throw new ArgumentNullException("keys");
      Array.Sort<TKey, TValue>(keys, items, 0, keys.Length, (IComparer<TKey>) null);
    }

    /// <summary>
    /// Sorts the elements in a range of elements in an <see cref="T:System.Array"/> using the <see cref="T:System.IComparable`1"/> generic interface implementation of each element of the <see cref="T:System.Array"/>.
    /// </summary>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to sort</param><param name="index">The starting index of the range to sort.</param><param name="length">The number of elements in the range to sort.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="index"/> and <paramref name="length"/> do not specify a valid range in <paramref name="array"/>.</exception><exception cref="T:System.InvalidOperationException">One or more elements in <paramref name="array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort<T>(T[] array, int index, int length)
    {
      Array.Sort<T>(array, index, length, (IComparer<T>) null);
    }

    /// <summary>
    /// Sorts a range of elements in a pair of <see cref="T:System.Array"/> objects (one contains the keys and the other contains the corresponding items) based on the keys in the first <see cref="T:System.Array"/> using the <see cref="T:System.IComparable`1"/> generic interface implementation of each key.
    /// </summary>
    /// <param name="keys">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the keys to sort. </param><param name="items">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the items that correspond to the keys in <paramref name="keys"/>, or null to sort only <paramref name="keys"/>.</param><param name="index">The starting index of the range to sort.</param><param name="length">The number of elements in the range to sort.</param><typeparam name="TKey">The type of the elements of the key array.</typeparam><typeparam name="TValue">The type of the elements of the items array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="keys"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="keys"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="items"/> is not null, and the lower bound of <paramref name="keys"/> does not match the lower bound of <paramref name="items"/>.-or-<paramref name="items"/> is not null, and the length of <paramref name="keys"/> is greater than the length of <paramref name="items"/>.-or-<paramref name="index"/> and <paramref name="length"/> do not specify a valid range in the <paramref name="keys"/><see cref="T:System.Array"/>.-or-<paramref name="items"/> is not null, and <paramref name="index"/> and <paramref name="length"/> do not specify a valid range in the <paramref name="items"/><see cref="T:System.Array"/>.</exception><exception cref="T:System.InvalidOperationException">One or more elements in the <paramref name="keys"/><see cref="T:System.Array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, int index, int length)
    {
      Array.Sort<TKey, TValue>(keys, items, index, length, (IComparer<TKey>) null);
    }

    /// <summary>
    /// Sorts the elements in an <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface.
    /// </summary>
    /// <param name="array">The one-dimensional, zero-base <see cref="T:System.Array"/> to sort</param><param name="comparer">The <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface implementation to use when comparing elements, or null to use the <see cref="T:System.IComparable`1"/> generic interface implementation of each element.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in <paramref name="array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception><exception cref="T:System.ArgumentException">The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort<T>(T[] array, IComparer<T> comparer)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      Array.Sort<T>(array, 0, array.Length, comparer);
    }

    /// <summary>
    /// Sorts a pair of <see cref="T:System.Array"/> objects (one contains the keys and the other contains the corresponding items) based on the keys in the first <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface.
    /// </summary>
    /// <param name="keys">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the keys to sort. </param><param name="items">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the items that correspond to the keys in <paramref name="keys"/>, or null to sort only <paramref name="keys"/>.</param><param name="comparer">The <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface implementation to use when comparing elements, or null to use the <see cref="T:System.IComparable`1"/> generic interface implementation of each element.</param><typeparam name="TKey">The type of the elements of the key array.</typeparam><typeparam name="TValue">The type of the elements of the items array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="keys"/> is null.</exception><exception cref="T:System.ArgumentException"><paramref name="items"/> is not null, and the lower bound of <paramref name="keys"/> does not match the lower bound of <paramref name="items"/>.-or-<paramref name="items"/> is not null, and the length of <paramref name="keys"/> is greater than the length of <paramref name="items"/>.-or-The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in the <paramref name="keys"/><see cref="T:System.Array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, IComparer<TKey> comparer)
    {
      if (keys == null)
        throw new ArgumentNullException("keys");
      Array.Sort<TKey, TValue>(keys, items, 0, keys.Length, comparer);
    }

    /// <summary>
    /// Sorts the elements in a range of elements in an <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface.
    /// </summary>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to sort.</param><param name="index">The starting index of the range to sort.</param><param name="length">The number of elements in the range to sort.</param><param name="comparer">The <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface implementation to use when comparing elements, or null to use the <see cref="T:System.IComparable`1"/> generic interface implementation of each element.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="array"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="index"/> and <paramref name="length"/> do not specify a valid range in <paramref name="array"/>. -or-The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in <paramref name="array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [SecuritySafeCritical]
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    public static void Sort<T>(T[] array, int index, int length, IComparer<T> comparer)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (index < 0 || length < 0)
        throw new ArgumentOutOfRangeException(length < 0 ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      if (array.Length - index < length)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
      if (length <= 1 || (comparer == null || comparer == Comparer<T>.Default) && Array.TrySZSort((Array) array, (Array) null, index, index + length - 1))
        return;
      ArraySortHelper<T>.Default.Sort(array, index, length, comparer);
    }

    /// <summary>
    /// Sorts a range of elements in a pair of <see cref="T:System.Array"/> objects (one contains the keys and the other contains the corresponding items) based on the keys in the first <see cref="T:System.Array"/> using the specified <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface.
    /// </summary>
    /// <param name="keys">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the keys to sort. </param><param name="items">The one-dimensional, zero-based <see cref="T:System.Array"/> that contains the items that correspond to the keys in <paramref name="keys"/>, or null to sort only <paramref name="keys"/>.</param><param name="index">The starting index of the range to sort.</param><param name="length">The number of elements in the range to sort.</param><param name="comparer">The <see cref="T:System.Collections.Generic.IComparer`1"/> generic interface implementation to use when comparing elements, or null to use the <see cref="T:System.IComparable`1"/> generic interface implementation of each element.</param><typeparam name="TKey">The type of the elements of the key array.</typeparam><typeparam name="TValue">The type of the elements of the items array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="keys"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than the lower bound of <paramref name="keys"/>.-or-<paramref name="length"/> is less than zero.</exception><exception cref="T:System.ArgumentException"><paramref name="items"/> is not null, and the lower bound of <paramref name="keys"/> does not match the lower bound of <paramref name="items"/>.-or-<paramref name="items"/> is not null, and the length of <paramref name="keys"/> is greater than the length of <paramref name="items"/>.-or-<paramref name="index"/> and <paramref name="length"/> do not specify a valid range in the <paramref name="keys"/><see cref="T:System.Array"/>.-or-<paramref name="items"/> is not null, and <paramref name="index"/> and <paramref name="length"/> do not specify a valid range in the <paramref name="items"/><see cref="T:System.Array"/>. -or-The implementation of <paramref name="comparer"/> caused an error during the sort. For example, <paramref name="comparer"/> might not return 0 when comparing an item with itself.</exception><exception cref="T:System.InvalidOperationException"><paramref name="comparer"/> is null, and one or more elements in the <paramref name="keys"/><see cref="T:System.Array"/> do not implement the <see cref="T:System.IComparable`1"/> generic interface.</exception>
    [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
    [SecuritySafeCritical]
    public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, int index, int length, IComparer<TKey> comparer)
    {
      if (keys == null)
        throw new ArgumentNullException("keys");
      if (index < 0 || length < 0)
        throw new ArgumentOutOfRangeException(length < 0 ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
      if (keys.Length - index < length || items != null && index > items.Length - length)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
      if (length <= 1 || (comparer == null || comparer == Comparer<TKey>.Default) && Array.TrySZSort((Array) keys, (Array) items, index, index + length - 1))
        return;
      ArraySortHelper<TKey, TValue>.Default.Sort(keys, items, index, length, comparer);
    }

    /// <summary>
    /// Sorts the elements in an <see cref="T:System.Array"/> using the specified <see cref="T:System.Comparison`1"/>.
    /// </summary>
    /// <param name="array">The one-dimensional, zero-based <see cref="T:System.Array"/> to sort</param><param name="comparison">The <see cref="T:System.Comparison`1"/> to use when comparing elements.</param><typeparam name="T">The type of the elements of the array.</typeparam><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.-or-<paramref name="comparison"/> is null.</exception><exception cref="T:System.ArgumentException">The implementation of <paramref name="comparison"/> caused an error during the sort. For example, <paramref name="comparison"/> might not return 0 when comparing an item with itself.</exception>
    public static void Sort<T>(T[] array, Comparison<T> comparison)
    {
      if (array == null)
        throw new ArgumentNullException("array");
      if (comparison == null)
        throw new ArgumentNullException("comparison");
      IComparer<T> comparer = (IComparer<T>) new Array.FunctorComparer<T>(comparison);
      Array.Sort<T>(array, comparer);
    }

    /// <summary>
    /// Initializes every element of the value-type <see cref="T:System.Array"/> by calling the default constructor of the value type.
    /// </summary>
    [SecuritySafeCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public void Initialize();

    internal sealed class FunctorComparer<T> : IComparer<T>
    {
      private Comparer<T> c = Comparer<T>.Default;
      private Comparison<T> comparison;

      public FunctorComparer(Comparison<T> comparison)
      {
        this.comparison = comparison;
      }

      public int Compare(T x, T y)
      {
        return this.comparison(x, y);
      }
    }

    private struct SorterObjectArray
    {
      private object[] keys;
      private object[] items;
      private IComparer comparer;

      internal SorterObjectArray(object[] keys, object[] items, IComparer comparer)
      {
        if (comparer == null)
          comparer = (IComparer) Comparer.Default;
        this.keys = keys;
        this.items = items;
        this.comparer = comparer;
      }

      internal void SwapIfGreaterWithItems(int a, int b)
      {
        if (a == b)
          return;
        try
        {
          if (this.comparer.Compare(this.keys[a], this.keys[b]) <= 0)
            return;
          object obj1 = this.keys[a];
          this.keys[a] = this.keys[b];
          this.keys[b] = obj1;
          if (this.items == null)
            return;
          object obj2 = this.items[a];
          this.items[a] = this.items[b];
          this.items[b] = obj2;
        }
        catch (IndexOutOfRangeException ex)
        {
          throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", this.keys[b], (object) this.keys[b].GetType().Name, (object) this.comparer));
        }
        catch (Exception ex)
        {
          throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
        }
      }

      internal void QuickSort(int left, int right)
      {
        do
        {
          int index1 = left;
          int index2 = right;
          int median = Array.GetMedian(index1, index2);
          this.SwapIfGreaterWithItems(index1, median);
          this.SwapIfGreaterWithItems(index1, index2);
          this.SwapIfGreaterWithItems(median, index2);
          object obj1 = this.keys[median];
          do
          {
            try
            {
              while (this.comparer.Compare(this.keys[index1], obj1) < 0)
                ++index1;
              while (this.comparer.Compare(obj1, this.keys[index2]) < 0)
                --index2;
            }
            catch (IndexOutOfRangeException ex)
            {
              throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", obj1, (object) obj1.GetType().Name, (object) this.comparer));
            }
            catch (Exception ex)
            {
              throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
            }
            if (index1 <= index2)
            {
              if (index1 < index2)
              {
                object obj2 = this.keys[index1];
                this.keys[index1] = this.keys[index2];
                this.keys[index2] = obj2;
                if (this.items != null)
                {
                  object obj3 = this.items[index1];
                  this.items[index1] = this.items[index2];
                  this.items[index2] = obj3;
                }
              }
              ++index1;
              --index2;
            }
            else
              break;
          }
          while (index1 <= index2);
          if (index2 - left <= right - index1)
          {
            if (left < index2)
              this.QuickSort(left, index2);
            left = index1;
          }
          else
          {
            if (index1 < right)
              this.QuickSort(index1, right);
            right = index2;
          }
        }
        while (left < right);
      }
    }

    private struct SorterGenericArray
    {
      private Array keys;
      private Array items;
      private IComparer comparer;

      internal SorterGenericArray(Array keys, Array items, IComparer comparer)
      {
        if (comparer == null)
          comparer = (IComparer) Comparer.Default;
        this.keys = keys;
        this.items = items;
        this.comparer = comparer;
      }

      internal void SwapIfGreaterWithItems(int a, int b)
      {
        if (a == b)
          return;
        try
        {
          if (this.comparer.Compare(this.keys.GetValue(a), this.keys.GetValue(b)) <= 0)
            return;
          object obj1 = this.keys.GetValue(a);
          this.keys.SetValue(this.keys.GetValue(b), a);
          this.keys.SetValue(obj1, b);
          if (this.items == null)
            return;
          object obj2 = this.items.GetValue(a);
          this.items.SetValue(this.items.GetValue(b), a);
          this.items.SetValue(obj2, b);
        }
        catch (IndexOutOfRangeException ex)
        {
          throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", this.keys.GetValue(b), (object) this.keys.GetValue(b).GetType().Name, (object) this.comparer));
        }
        catch (Exception ex)
        {
          throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
        }
      }

      internal void QuickSort(int left, int right)
      {
        do
        {
          int num1 = left;
          int num2 = right;
          int median = Array.GetMedian(num1, num2);
          this.SwapIfGreaterWithItems(num1, median);
          this.SwapIfGreaterWithItems(num1, num2);
          this.SwapIfGreaterWithItems(median, num2);
          object obj1 = this.keys.GetValue(median);
          do
          {
            try
            {
              while (this.comparer.Compare(this.keys.GetValue(num1), obj1) < 0)
                ++num1;
              while (this.comparer.Compare(obj1, this.keys.GetValue(num2)) < 0)
                --num2;
            }
            catch (IndexOutOfRangeException ex)
            {
              throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", obj1, (object) obj1.GetType().Name, (object) this.comparer));
            }
            catch (Exception ex)
            {
              throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
            }
            if (num1 <= num2)
            {
              if (num1 < num2)
              {
                object obj2 = this.keys.GetValue(num1);
                this.keys.SetValue(this.keys.GetValue(num2), num1);
                this.keys.SetValue(obj2, num2);
                if (this.items != null)
                {
                  object obj3 = this.items.GetValue(num1);
                  this.items.SetValue(this.items.GetValue(num2), num1);
                  this.items.SetValue(obj3, num2);
                }
              }
              if (num1 != int.MaxValue)
                ++num1;
              if (num2 != int.MinValue)
                --num2;
            }
            else
              break;
          }
          while (num1 <= num2);
          if (num2 - left <= right - num1)
          {
            if (left < num2)
              this.QuickSort(left, num2);
            left = num1;
          }
          else
          {
            if (num1 < right)
              this.QuickSort(num1, right);
            right = num2;
          }
        }
        while (left < right);
      }
    }

    private sealed class SZArrayEnumerator : IEnumerator, ICloneable
    {
      private Array _array;
      private int _index;
      private int _endIndex;

      public object Current
      {
        get
        {
          if (this._index < 0)
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
          if (this._index >= this._endIndex)
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));
          else
            return this._array.GetValue(this._index);
        }
      }

      internal SZArrayEnumerator(Array array)
      {
        this._array = array;
        this._index = -1;
        this._endIndex = array.Length;
      }

      public object Clone()
      {
        return this.MemberwiseClone();
      }

      public bool MoveNext()
      {
        if (this._index >= this._endIndex)
          return false;
        ++this._index;
        return this._index < this._endIndex;
      }

      public void Reset()
      {
        this._index = -1;
      }
    }

    private sealed class ArrayEnumerator : IEnumerator, ICloneable
    {
      private Array array;
      private int index;
      private int endIndex;
      private int startIndex;
      private int[] _indices;
      private bool _complete;

      public object Current
      {
        get
        {
          if (this.index < this.startIndex)
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
          if (this._complete)
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));
          else
            return this.array.GetValue(this._indices);
        }
      }

      internal ArrayEnumerator(Array array, int index, int count)
      {
        this.array = array;
        this.index = index - 1;
        this.startIndex = index;
        this.endIndex = index + count;
        this._indices = new int[array.Rank];
        int num = 1;
        for (int dimension = 0; dimension < array.Rank; ++dimension)
        {
          this._indices[dimension] = array.GetLowerBound(dimension);
          num *= array.GetLength(dimension);
        }
        --this._indices[this._indices.Length - 1];
        this._complete = num == 0;
      }

      private void IncArray()
      {
        int rank = this.array.Rank;
        ++this._indices[rank - 1];
        for (int dimension1 = rank - 1; dimension1 >= 0; --dimension1)
        {
          if (this._indices[dimension1] > this.array.GetUpperBound(dimension1))
          {
            if (dimension1 == 0)
            {
              this._complete = true;
              break;
            }
            else
            {
              for (int dimension2 = dimension1; dimension2 < rank; ++dimension2)
                this._indices[dimension2] = this.array.GetLowerBound(dimension2);
              ++this._indices[dimension1 - 1];
            }
          }
        }
      }

      public object Clone()
      {
        return this.MemberwiseClone();
      }

      public bool MoveNext()
      {
        if (this._complete)
        {
          this.index = this.endIndex;
          return false;
        }
        else
        {
          ++this.index;
          this.IncArray();
          return !this._complete;
        }
      }

      public void Reset()
      {
        this.index = this.startIndex - 1;
        int num = 1;
        for (int dimension = 0; dimension < this.array.Rank; ++dimension)
        {
          this._indices[dimension] = this.array.GetLowerBound(dimension);
          num *= this.array.GetLength(dimension);
        }
        this._complete = num == 0;
        --this._indices[this._indices.Length - 1];
      }
    }
  }
}
